﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using COM.Rights.Model;
using COM.Rights.BLL;

public partial class Pages_TUser_PwdUpdate : System.Web.UI.Page
{
    protected string UID
    {
        get
        {
            if (!string.IsNullOrEmpty(ZASession.Account))
                return ZASession.Account;
            else
                return null;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Bind();
    }

    protected void Bind()
    {
        TUser bll = new TUser();
        TUserInfo info = bll.GetModel("", "UID=@UID", "", new List<DBParameter>() { new DBParameter("@UID", UID) });
        TUser_UID.Text = UID;
        TUser_Name.Text = info.Name;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        TUser bll = new TUser();
        TUserInfo info = bll.GetModel("", "UID=@UID", "", new List<DBParameter>() { new DBParameter("@UID", UID) });

        if (!string.IsNullOrEmpty(txtOldPwd.Value.Trim()))
        {
            if (txtOldPwd.Value.Trim() != info.PWD)
            {
                lbOldPwd.Text = "<font color='red'>请重新输入旧密码！</font>";
                return;
            }
            else
            {
                lbOldPwd.Text = null;

                if (!string.IsNullOrEmpty(TUser_PWD.Value.Trim()) && !string.IsNullOrEmpty(confirmPWD.Value.Trim()))
                {
                    if (TUser_PWD.Value.Trim() != confirmPWD.Value.Trim())
                    {
                        lbConfim.Text = "<font color='red'>两次新密码输入不一致！</font>";
                        return;
                    }
                    else
                    {
                        lbConfim.Text = null;
                    }
                }
                //else
                //{
                //    lbConfim.Text = "<font color='red'>请输入确认密码和确认密码！</font>";
                //    return;
                //}
                try
                {
                    info.PWD = TUser_PWD.Value.Trim();
                    bll.Update(info, "");
                    Response.Write("<script>alert('密码修改成功！');</script>");
                }
                catch (Exception ex)
                {
                    Response.Write("<script>alert('密码修改失败！" + ex.ToString() + "');</script>");
                }
            }
        }
        //else
        //{
        //    lbOldPwd.Text = "<font color='red'>请输入旧密码！</font>";
        //    return;
        //}
    }
}